/**
 * @author luguoxiang
 * @date 2022/7/5
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { createApi, nextId, request } from '@/soar';
import mock from '@/utils/mockUtils';

const basePath = '/system/user';
const subject = '用户';
const api = createApi(basePath, subject);

// api 使用 mock
mock.mockApi(api, {
  // 数据定义，预生成数据时对必填字段值填充，可以是函数和固定值
  data: {
    image: 'http://localhost:8000/src/assets/app/logo.png', // 固定值
    string: (i: number) => mock.name(),
    number: (i: number) => mock.number(0, 9999),
    boolean1: (i: number) => mock.boolean(),
    boolean2: (i: number) => i % 2,
    datetime: (i: number) => mock.datetime(),
    date: (i: number) => mock.datetime(),
    time: (i: number) => mock.datetime(),
    dict: (i: number) => i % 3,
    remote: (i: number) => nextId(),
    enum1: (i: number) => i % 3,
    enum2: (i: number) => mock.element(['a', 'b', 'c']),
    enum3: (i: number) => i % 3,
    enum4: (i: number) => mock.element(['a', 'b', 'c']),
    enum5: (i: number) => i % 3,
    enum6: (i: number) => mock.element(['a', 'b', 'c']),
    predicate: 'admin角色 和 超级管理员用户可见',
  },
  // 默认值生成，新增修改时对非必填字段生成值
  defaultValue: {
    image: (v: string) => 'http://localhost:8000/src/assets/app/logo.png',
  },
  timeout: [100, 500],
});

export default {
  ...api,
  /**
   * 自定义接口（增加其他接口）
   * @param params
   */
  page(params: any) {
    return request.get(`${basePath}/page`, { params });
  },
};
